﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FinancialReportPowerPointAddIn.Helper
{
    public class FinancialReportContext:DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {            
            //DirectoryInfo info = new DirectoryInfo(Directory.GetCurrentDirectory());
            DirectoryInfo info = new DirectoryInfo("G:\\financial-report-for-ppt\\FinancialReportPowerPointAddIn");
            if (File.Exists(string.Format(@"{0}\App_Data\FinancialReport.mdf", info.FullName)))
            {
                optionsBuilder.UseSqlServer(string.Format(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename={0}\App_Data\FinancialReport.mdf;Integrated Security=True;Connect Timeout=30", info.FullName));
            }
            else
            {
                optionsBuilder.UseSqlServer(string.Format(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename={0}\App_Data\FinancialReport.mdf;Integrated Security=True;Connect Timeout=30", info.Parent?.Parent?.Parent?.FullName));
            }
        }

        public DbSet<PLData> PLDatas { get; set; }
        public DbSet<Fob> Fobs { get; set; }
        public DbSet<PlatformSales> PlatformSales { get; set; }
        public DbSet<PeakHourSales> PeakHourSales { get; set; }
        public DbSet<ManageNumber> ManageNumbers { get; set; }
        public DbSet<CrewLabor> CrewLabors { get; set; }
        public DbSet<MdsQuantity> MdsQuantities { get; set; }
        public DbSet<BalanceSheet> BalanceSheets { get; set; }
        public DbSet<ProfitSheet> ProfitSheets { get; set; }
    }
}
